package com.zkca.xf.base;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.github.ybq.android.spinkit.SpinKitView;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
import com.zkca.xf.R;

import java.lang.reflect.Field;

/**
 * Created by zkfr on 2017/11/9.
 */

public abstract class BaseTitleActivity extends BaseActivity  {
    private RelativeLayout llRoot;
    private LinearLayout baseTile;
    private RelativeLayout llBasetitleBack;
    private TextView tvBaseTitle;
    private ImageView im_base_left;
    private TextView tv_basetitle_back;
    private ImageView im_base_right;
    private TextView tv_basetitle_right;
    private RelativeLayout spinKitView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        if (Build.VERSION.SDK_INT >= 21) {
//            View decorView = getWindow().getDecorView();
//            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
//            getWindow().setStatusBarColor(Color.TRANSPARENT);
//        }

        super.setContentView(R.layout.layout_base_title);
        initView();
    }
    @Override
    public void setContentView(int resId) {
        View view = getLayoutInflater().inflate(resId, null);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        lp.addRule(RelativeLayout.BELOW, R.id.ll_basetitle);
        if (null != llRoot)
            llRoot.addView(view, lp);

    }
    private void initView() {
        llRoot = (RelativeLayout) findViewById(R.id.ll_basetitle_root);
        llBasetitleBack = (RelativeLayout) findViewById(R.id.ll_basetitle_back);
        tvBaseTitle = (TextView) findViewById(R.id.tv_base_title);
        tv_basetitle_back = (TextView) findViewById(R.id.tv_basetitle_back);
        im_base_left= (ImageView) findViewById(R.id.im_base_left);
        tv_basetitle_right = (TextView) findViewById(R.id.tv_basetitle_right);
        im_base_right= (ImageView) findViewById(R.id.im_base_right);
        spinKitView=(RelativeLayout)findViewById(R.id.spin_kit);
        baseTile=findViewById(R.id.ll_basetitle);
        llBasetitleBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               backActivity();
            }
        });
    }


    /**
     *
     * 设置中间标题文字
     * @param c
     */
    public void setTitleText(String c) {
        if (tvBaseTitle != null)
            tvBaseTitle.setText(c);
    }

    /**
     * 加载框,是否显示
     *
     * @param show
     */
    public void showSpinKitLoading(boolean show) {
        if (show) {
            spinKitView.setVisibility(View.VISIBLE);
        } else {
            spinKitView.setVisibility(View.GONE);
        }
    }
    /**
     * 设置右边标题
     * @param c
     */
    public void setTextRight(CharSequence c) {
        if (tv_basetitle_right != null)
            tv_basetitle_right.setText(c);
    }
    /**
     * 设置左边文字是否显示
     */
    public void setleftTextVisibility(boolean b){

        if (tv_basetitle_back != null) {
            if (b)
                tv_basetitle_back.setVisibility(View.VISIBLE);
            else
                tv_basetitle_back.setVisibility(View.GONE);
        }
    }
    /**
     * 设置左边图片是否显示
     */
    public void setleftImgVisibility(boolean b){
        if (im_base_left != null) {
            if (b)
                im_base_left.setVisibility(View.VISIBLE);
            else
                im_base_left.setVisibility(View.GONE);
        }
    }
    /**
     * 设置右边文字是否显示
     */
    public void setrightTextVisibility(boolean b){
        if (tv_basetitle_right != null) {
            if (b)
                tv_basetitle_right.setVisibility(View.VISIBLE);
            else
                tv_basetitle_right.setVisibility(View.GONE);
        }
    }
    /**
     * 设置右边图片是否显示
     */
    public void setImgVisibility(boolean b){
        if (im_base_right != null) {
            if (b)
                im_base_right.setVisibility(View.VISIBLE);
            else
                im_base_right.setVisibility(View.GONE);
        }
    }

    /**
     * 设置右边按钮是否显示
     * @param
     */
    public void setTitleBarVisibility(boolean b){
        if (b){
            baseTile.setVisibility(View.VISIBLE);
        }else {
            baseTile.setVisibility(View.GONE);
        }
    }
    public RelativeLayout getBaseTitleBar() {
        return llRoot;
    }
    public TextView getTvBaseTitle() {
        return tvBaseTitle;
    }
    public TextView getTVleft() {
        return tv_basetitle_back;
    }
    public TextView getTVRight() {
        return tv_basetitle_right;
    }
    public ImageView getImgleft() {
        return im_base_left;
    }
    public ImageView getImgRight() {
        return im_base_right;
    }


}

